package edu.wlu.cs.levy.kdTree.demo;

import edu.wlu.cs.levy.kdTree.KDTree;

public class KDDemo {

	public static void main(String [] args) {

		//	double [] A = {2, 5};
		//	double [] B = {1, 1};
		//	double [] C = {3, 9};
		//	double [] T = {1, 10};

		double [] A = {2};
		double [] B = {1};
		double [] C = {3};
		double [] T = {4};

		// make a KD-tree and add some nodes
		KDTree kd = new KDTree(1);
		try {
			kd.insert(A, "AAA");
			kd.insert(B, "BBB");
			kd.insert(C, "CCC");
		}
		catch (Exception e) {
			System.err.println(e);
		}


		// look for node B
		try {
			String n = (String)kd.search(B);
			System.err.println(n);

		}
		catch (Exception e) {
			System.err.println(e);
		}

		try {

			// find T's nearest neighbor, which should be C
			String n = (String)kd.nearest(T);
			System.err.println(n);

			// remove C from the tree
			kd.delete(C);

			// now T's nearest neighbor should be A
			n = (String)kd.nearest(T);
			System.err.println(n);
		}
		catch (Exception e) {
			System.err.println(e);
		}
	}

}
